if(typeof Ext.user.method.paibanidstore == 'undefined'){ Ext.user.method.paibanidstore = Ext.user.method.paibanid();}

Ext.user.timeanpaicolumns = [];
Ext.user.timeanpaicolumns[0] =  { xtype: 'gridcolumn', dataIndex: 'id', header: '编号', sortable: true};
Ext.user.timeanpaicolumns[1] =  { xtype: 'gridcolumn', dataIndex: 'account', header: '帐号', sortable: true};
Ext.user.timeanpaicolumns[2] =  { xtype: 'gridcolumn', dataIndex: 'nickname', header: '姓名', sortable: true};
Ext.user.timeanpaicolumns[3] =  { xtype: 'gridcolumn', dataIndex: 'type', header: '排班情况', sortable: true,renderer:Ext.user.renderer.paiban};
Ext.user.timeanpaicolumns[4] =  { xtype: 'gridcolumn', dataIndex: 'intro', header: '备注事项', sortable: true};

Ext.user.timeanpaitbara = [
	{xtype:'panel',columnWidth: 0.06,items:[{xtype:'panel',style:'margin-left:5px;margin-right:5px;line-height:20px;',html:'值班时间:'},]},
	{xtype:'panel',columnWidth: 0.09,items:[{name:'searchdate',xtype:'datefield'}]},
	{xtype:'panel',style:'margin-left:5px;',columnWidth: 0.04,items:[{xtype:'button',text:'查  找',handler:function(){
		var time = Ext.getCmp('anpaisearch').form.getValues().searchdate;
		var searchtime = function (m) { return new Date(Ext.user.method.dateday(time,m)).dateFormat('Y-m-d'); };
		var panel = Ext.getCmp('timeanpaipanel');
		panel.removeAll();
		var aa= (Ext.get('timeanpaipanel').query('*[class=x-panel-body]'))[0].id;
		for(var i=0;i<7;i++){
			panel.add(new Ext.user.timeanpaifunc({title:searchtime(i)}).render(aa));
		}
	}}]}
];
Ext.user.timeanpaitbar = {border:true,frame:true,id:'anpaisearch',xtype:'form',title:'',height:40,layout: 'column',items:Ext.user.timeanpaitbara}
Ext.user.timeanpaifunc = function(cfg){
	this.cfg = cfg || {};
	this.date = this.cfg.title;
	
	this.timeanpaidata = new Ext.data.JsonStore({
	   fields: [
			'id','account','type','intro','nickname','date'
		],
		storeId:'timeanpai_' + this.date,
		url: Ext.user.baseUrl + '/Works/data/',
		root:'list',
		totalProperty: 'count',
		autoLoad:true,
		baseParams:{'date':this.date}
	});	
	return new Ext.grid.GridPanel({
			xtype:'grid',
			title:this.cfg.title,
            id:this.cfg.id || '',
			border: false,
			width:window.parent.Ext.getCmp('center_90').getWidth()-19,
			autoHeight:true,
			columnLines: true, 
			trackMouseOver:true,
			columnLines:true,
			viewConfig: {forceFit: true},
			listeners:{
				rowdblclick:function(g, n, e){
					var time = Ext.getCmp('anpaisearch').form.getValues().searchdate;
					if(time == ''){
						var date = new Date();
					}else{
						var date = new Date(time);
					}
					if( date.dateFormat('Y-m-d') == this.title || date.dateFormat('d') < new Date(this.title).dateFormat('d')){
						//g.getSelectionModel().getSelected().id;
						var aa = new Ext.user.timeanpaiWindow({edit:true});
						aa.show();
						Ext.user.method.loaddataForm({
							url:'/Works/data/',
							params:{where:g.getSelectionModel().getSelected().id,do:'id',date:this.title},
							Formid:'timeanpaiform',
							method:'POST',
							recorddata:['uid','type','intro']
						});
							//alert(g.getSelectionModel().getSelected().id);
						Ext.getCmp('timeanpaiform').add(new Ext.form.Hidden({name:'uid',value:g.getSelectionModel().getSelected().id,renderTo:'timeanpaiformid'}));
						Ext.getCmp('timeanpaiform').add(new Ext.form.Hidden({name:'dates',value:this.title,renderTo:'timeanpaiformid'}));
						
						
					}
				}
			},
			cm:new Ext.grid.ColumnModel(Ext.user.timeanpaicolumns),
			store:this.timeanpaidata,
		});
}
//Ext.user.timeanpaitime = new Date();
//Ext.user.timeanpaitimeD = Ext.user.timeanpaitime.dateFormat('d');
//Ext.user.timeanpaitimeL = Ext.user.timeanpaitimeD-3;
Ext.user.timeanpaitime = function (m) { return new Date(Ext.user.method.dateday(new Date(),m)).dateFormat('Y-m-d'); };

Ext.user.timeanpaigird = [];
for(var i=0; i<7;i++){
	Ext.user.timeanpaigird[i] = new Ext.user.timeanpaifunc({title:Ext.user.timeanpaitime(i-3)});
}
Ext.user.timeanpai = Ext.extend(Ext.Panel, {
	title:'值日管理',
	id:'timeanpaipanel',
	height:window.parent.Ext.getCmp('center_90').getHeight(),
	autoScroll:true,
	tbar:Ext.user.timeanpaitbar,
	initComponent:function(){
		this.items = [Ext.user.timeanpaigird];
		Ext.user.timeanpai.superclass.initComponent.call(this);
	}
});




Ext.user.timeanpaiWindow = Ext.extend(Ext.Window, {
    title: '添加值日情况',
    width: 400,
	id:'timeanpaiWindow',
    autoHeight:true,
    border: false,
	modal:true,
	listeners:{
		close:function(a){
				Ext.user.centermenu.setDisabled(false);
			  }
	},
	button:function(){
		Ext.apply(this,this.cfg);
		if(typeof this.edit != 'undefined'){
			this.buttons = [{text:'修改值日人员',handler:function(){
				Ext.user.method.submitForm('timeanpaiform','/Works/edit/',{s:function(){
					var date = Ext.getCmp('timeanpaiform').form.getValues().dates;
					Ext.getCmp('timeanpaiWindow').close();
					Ext.StoreMgr.lookup('timeanpai_'+date).reload();
					
				},f:function(){
					//alert('添加失败');
				}},'POST');
			}},{text:'重置',handler:function(){
					Ext.getCmp('timeanpaiform').form.reset();
			}}];		
		}
	},
    initComponent: function(cfg) {
		this.cfg = cfg || {};
		this.button();
        this.items = [
            {
                xtype: 'form',
                id: 'timeanpaiform',
				formId:'timeanpaiformid',
                border: false,
                items: [
                    {
                        xtype: 'fieldset',
                        title: '基本信息',
                        style: 'margin:5px;',
                        items: [
                           {
								xtype: 'combo',
								fieldLabel: '排班情况',
								anchor: '50%',
								name:'type', 
								store: Ext.user.method.paibanidstore,
								displayField:'text',
								valueField:'id',
								hiddenName:'type',
								hiddenValue:'1',
								editable:false,
								typeAhead: true,
								forceSelection: true,
								mode: 'local',
								triggerAction: 'all',
								emptyText:'请选择',
								selectOnFocus:true,	
                            },
                          
							{
                                xtype: 'textarea',
                                anchor: '100%',
                                fieldLabel: '备注',
                                name: 'intro'
                            }
                        ]
                    }
                ]
            }
        ];
        Ext.user.timeanpaiWindow.superclass.initComponent.call(this);
    }
});
